package com.sunshuo.springsecuritydemo.service;

import com.sunshuo.springsecuritydemo.dao.UserDao;
import com.sunshuo.springsecuritydemo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * @ClassName UserService
 * @Description
 * @Author sunshuo
 * @Date 2021/11/6 20:22
 */
@Service
public class UserService {

    private UserDao userDao;

    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    public User findUserByUsername(String username) {
        try {
            return userDao.findUserByUsername(username);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public List<User> getUsers() {
        try {
            List<User> users = userDao.getUsers();
            return users;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

}
